<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>事件绑定</title>
    <style>
      .box{
        width: 400px;
        height: 300px;
        background: #eaf;
      }
      body{
        height: 20000px;
      }
      hr{
        margin: 50px 0;
      }
    </style>
  </head>
  <body>
    <div id="root"></div>
    <script src="./js/react.development.js"></script>
    <script src="./js/react-dom.development.js"></script>
    <script src="./js/babel.min.js"></script>

    <script type="text/babel">

      //声明函数
      function callback(){
        alert('你点击了我 ~~~ 外部声明函数');
      }

      let obj = {
        fn: () => {
          alert('点击我 ~~ 对象的方法')
        }
      }

      //声明虚拟 DOM 对象
      let vdom = <div>
          <h2>绑定事件</h2>
          <button onClick={function(){
            alert('你点击了我~~')
          }}>点我</button>

          <button onClick={() => {
            alert('你点击了我~~箭头函数')
          }}>点我</button>

          <button onClick={callback}>点我</button>
          <button onClick={obj.fn}>点我</button>
          <hr />

          
          <h2>事件源</h2>
          <div className="box" onMouseOver={e => {
            //鼠标移入之后 改变元素的背景颜色
            // console.log(e.target);
            e.target.style.background = '#aef';
          }}></div>
          <hr />

          <h2>阻止默认行为</h2>
          <a onClick={e => {
            //阻止默认行为
            e.preventDefault();
          }} href="http://www.atguigu.com">尚硅谷</a>

          <hr />
          <h2>事件对象 e 是一个合成事件</h2>
          <button onClick={(e) => {
            console.log(e)
          }}>点击查看事件对象</button>

          <hr />
          <h2>input 元素的 onchange 事件</h2>
          <input type="text" onChange={(e) => {
            console.log(e.target.value)
          }} />


        </div>;

      //渲染
      ReactDOM.render(vdom, document.querySelector('#root'))
    </script>
</body>
</html>
